package tianrun.ziguan.api.calculate.config.controller.asset;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tianrun.ziguan.api.calculate.config.dto.request.AssetGroupTreeSaveBody;
import tianrun.ziguan.api.calculate.config.service.asset.group.ITAssetGroupService;
import tianrun.ziguan.api.calculate.config.utils.HttpResponseTools;
import tianrun.ziguan.api.common.core.base.ResultBody;

import javax.validation.Valid;

@RestController
@RequestMapping("/assetGroup")
@Api(tags = "资产组")
public class AssetGroupController {

    private final ITAssetGroupService assetGroupService;

    public AssetGroupController(ITAssetGroupService assetGroupService) {
        this.assetGroupService = assetGroupService;
    }

    @ApiOperation(value = "获取资产组结构")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @GetMapping("/listByTree/{groupId}")
    public ResponseEntity<ResultBody> listByTree(@PathVariable Long groupId) {

        return HttpResponseTools.good(ResultBody.of(assetGroupService.listByTree(groupId)));
    }

    @ApiOperation(value = "保存资产组结构")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/saveByTree")
    public ResponseEntity<ResultBody> saveByTree(@RequestBody @Valid AssetGroupTreeSaveBody body) {
        return HttpResponseTools.good(ResultBody.of(assetGroupService.saveByTree(body)));
    }
}
